Skip to content

Conversation

Himmelschmidt
Copy link
Contributor

  1. Core Runtime Fix (packages/core)
  • Fixed BorrowMutError during rapid event firing (like browser autofill)
  • Restructured event handling to collect data first, then drop RefCell borrows before calling handlers
  • Added defensive try_borrow_mut() in ListenerCallback for edge cases
  1. TypeScript/JavaScript (packages/interpreter)
  • Added undefined checks for modifier keys at the start of serializeEvent()
  • Ensures all modifier keys default to false if undefined
  1. Rust - Web Event Handling (packages/web)
  • Added safe event conversion with dyn_into and fallback to default values
  • Removed unsafe unchecked_into conversions
  • Made ClipboardEvent use specific type instead of generic Event
  1. Rust - HTML Event Types (packages/html)
  • Added Default implementations for all event data types
  • Created EmptyEvent type as fallback for malformed events
  • Added #[serde(default)] to modifier keys in SerializedPointInteraction

Per my testing this seems to fix #4486

Browser autofill can cause multiple events to fire in rapid succession,
leading to nested RefCell borrows in the event handling system. This
resulted in 'already borrowed: BorrowMutError' crashes.

The root cause was that event handlers were called while RefCells for
'elements' and 'mounts' were still borrowed. When handlers modified the
DOM, they would try to borrow the same RefCells again, causing panics.

Fixed by restructuring event handling to:
1. Collect all necessary data (listeners, paths) while holding borrows
2. Drop all RefCell borrows before calling any event handlers
3. Execute handlers without any active borrows

This eliminates borrow conflicts while maintaining performance - cloning
AttributeValue::Listener is cheap as it only increments Rc counters.

Also added defensive try_borrow_mut() handling in ListenerCallback::call()
as additional safety for edge cases.

Fixes browser autofill crashes across all supported browsers.
Browser autofill can dispatch synthetic keyboard events where modifier keys
(altKey, ctrlKey, etc.) have undefined values instead of booleans. This
causes WASM binding errors when the undefined values are passed to Rust.

Added serde(default) attributes to all modifier key fields in
SerializedKeyboardData to gracefully handle undefined values by defaulting
them to false.

This fixes the 'expected a boolean argument, found undefined' errors that
occur during browser autofill scenarios.
Browser autofill can send keyboard, mouse, touch, and pointer events with
undefined modifier key properties (altKey, ctrlKey, metaKey, shiftKey).
This causes wasm-bindgen to throw "expected a boolean argument, found undefined"
errors when these events are serialized.

Added null coalescing operators (?? false) to all event serialization functions
to ensure modifier keys default to false when undefined.

Fixes browser autofill crashes in WASM applications.
Compiled TypeScript files to JavaScript using Bun after adding null
coalescing operators to handle undefined modifier keys in event serialization.

This completes the fix for browser autofill crashes by ensuring both the
Rust serde side and JavaScript serialization side handle undefined
modifier keys properly.
Browser autofill can send events with undefined modifier key properties
(altKey, ctrlKey, metaKey, shiftKey) and undefined string properties
(key, code). This causes wasm-bindgen to throw type assertion errors.

Added defensive property access using wasm_bindgen::JsValue conversion
with appropriate defaults:
- Boolean modifier keys default to false when undefined
- String properties default to "Unidentified" when undefined

This prevents "expected a boolean argument, found undefined" and
"expected a string argument, found undefined" errors during browser
autofill events.

Fixed in all event types that access modifier keys:
- KeyboardEvent, MouseEvent, WheelEvent, TouchEvent, DragEvent, PointerEvent
Added defensive null coalescing for KeyboardEvent key and code properties
in the TypeScript serialization layer. Browser autofill can send undefined
values for these properties, which was causing wasm-bindgen assertion errors.
Additional fixes for handling undefined properties in browser autofill events.
…rsions

- Add Default implementations for all event data types to handle browser autofill crashes gracefully
- Use specific ClipboardEvent type instead of generic Event for consistency
- Remove general unchecked_convert macro that was creating unnecessary unsafe conversions
- Keep safe conversions using dyn_into with fallback to default values
- Improve type consistency across all event converters

This ensures the browser autofill crash is properly handled while making the codebase safer by removing unnecessary unchecked type conversions.
@Himmelschmidt Himmelschmidt requested a review from a team as a code owner July 30, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WASM client crash on keyboard event being undefined

2 participants